package com.zshan.clinic.web.controller.medical;


import com.zshan.clinic.admin.entity.vo.ClinicFollowupDetailVo;
import com.zshan.clinic.admin.entity.vo.ClinicFollowupPageVo;
import com.zshan.clinic.admin.entity.vo.ClinicFollowupPatientVo;
import com.zshan.clinic.admin.entity.vo.ClinicFollowupRecordVo;
import com.zshan.clinic.admin.service.medical.ClinicFollowupService;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.database.model.ClinicFollowup;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;


/**
 * 随访
 * @author lichen
 */
@RestController
@RequestMapping("/clinic/followup")
public class ClinicFollowupController extends AbstractController {


    @Autowired
    private ClinicFollowupService clinicFollowupService;

    /**
     * 患者：查询患者随访记录
     * @param patientId 患者ID
     * @param visitDate 就诊日期
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getPatientFollowupList")
    public RestResp<PageInfo<ClinicFollowupPatientVo>> getPatientFollowupList(@RequestParam(name = "patientId") Long patientId,
                                                                             @RequestParam(name = "visitDate",required = false) LocalDate visitDate,
                                                                             @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                             @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<ClinicFollowupPatientVo> followupList = clinicFollowupService.getPatientFollowupList(userInfo.getClinicId(), patientId,visitDate,pageNo,pageSize);
        return RestResp.SUCCESS(followupList);
    }


    /**
     * 随访：查询随访列表
     * @param patientName
     * @param followupDate 随访日期 默认当天
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getFollowupList")
    public RestResp<List<ClinicFollowupPageVo>> getFollowupList(@RequestParam(name = "patientName",required = false) String patientName,
                                                                @RequestParam(name = "followupDate",required = false) LocalDate followupDate,
                                                                @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        List<ClinicFollowupPageVo> followupList = clinicFollowupService.getFollowupList(userInfo.getClinicId(),userInfo.getEmpId(),patientName,followupDate,pageNo,pageSize);
        return RestResp.SUCCESS(followupList);
    }

    /**
     * 随访：查询患者随访历史
     * @param patientId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getRecordList")
    public RestResp<List<ClinicFollowupRecordVo>> getRecordList(@RequestParam(name = "patientId",required = false) Long patientId,
                                                                @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        List<ClinicFollowupRecordVo> recordList = clinicFollowupService.getRecordList(userInfo.getClinicId(), patientId,pageNo,pageSize);
        return RestResp.SUCCESS(recordList);
    }

    /**
     * 随访：查询随访详情
     * @param followupId
     * @return
     */
    @GetMapping("/getFollowupDetail")
    public RestResp<ClinicFollowupDetailVo> getFollowupDetail(@RequestParam(name = "followupId") Long followupId) {
        UserInfo userInfo = getUserInfo();
        ClinicFollowupDetailVo clinicFollowupDetailVo = clinicFollowupService.getFollowupDetail(userInfo.getClinicId(), followupId);
        return RestResp.SUCCESS(clinicFollowupDetailVo);
    }

    /**
     * 随访：完成随访
     * @return
     */
    @PostMapping("/completeFollowup")
    public RestResp<Void> completeFollowup(@RequestBody ClinicFollowup clinicFollowup) {
        UserInfo userInfo = getUserInfo();
        clinicFollowup.setUpdateUserId(userInfo.getEmpId());
        clinicFollowup.setUpdateBy(userInfo.getEmpName());
        clinicFollowup.setClinicId(userInfo.getClinicId());
        clinicFollowupService.completeFollowup(clinicFollowup);
        return RestResp.SUCCESS();
    }
}
